package com.lzy.cloud.goods.service.GoodsServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.goods.dtos.CarSaleAppDto;
import com.lzy.cloud.goods.dtos.CarSaleDto;
import com.lzy.cloud.goods.entity.CarSale;
import com.lzy.cloud.goods.mapper.CarSaleMapperExt;
import com.lzy.cloud.goods.service.CarSaleService;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by WIN7 on 2018/6/9.
 */
@Service
public class CarSaleServiceImpl implements CarSaleService{

    @Autowired
    CarSaleMapperExt carSaleMapperExt;

    @Override
    public Long add(CarSaleDto dto) {
        CarSale carSale = DozerUtils.map(dto,CarSale.class);
        return carSaleMapperExt.insertSelective(carSale)>0?carSale.getId():null;
    }

    @Override
    public Boolean delById(Long id) {
        return carSaleMapperExt.deleteByPrimaryKey(id)>0;
    }

    @Override
    public Boolean update(CarSaleDto dto) {
        return carSaleMapperExt.updateByPrimaryKeySelective(DozerUtils.map(dto,CarSale.class))>0;
    }

    @Override
    public PageInfo<CarSaleDto> selectList(Pager pager, CarSaleDto dto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        return new PageInfo<>(carSaleMapperExt.selectList(dto));
    }

    @Override
    public CarSaleDto selectById(Long id) {
        return DozerUtils.map(carSaleMapperExt.selectByPrimaryKey(id),CarSaleDto.class);
    }

    @Override
    public CarSaleAppDto findById(Long id) {
        return carSaleMapperExt.findById(id);
    }

}
